<template>
	<view	class="ikz-login" v-if="!user_openinfo.nickname || !mobile">
      <button class="ikz-login-btn" v-if="!user_openinfo.nickname" @click.stop="getUserInfo" ></button>
      <button class="ikz-login-btn" v-else-if="!mobile" open-type="getPhoneNumber" @click.stop="aaa"  @getphonenumber.stop="getPhoneNumber"></button>
	</view>
</template>

<script>
  var app = getApp();
import ikz from '@/pages/Common/tools';
export default {
	name: 'loginbtn',
	props: {
	},
	data() {
		return {
      thrd_session:app.globalData.openUserInfo,
      user_openinfo:app.globalData.user_openinfo,
      mobile:app.globalData.mobile || '',
		};
	},
	mounted() {
    
  },
	methods: {
    aaa(){
      
    },
    getPhoneNumber(e){
      var that = this;
      if(e.detail.iv){
        var path = '/xyb/user_plat/get_wechat_mobile';
        var data = e.detail;
        ikz.post(path,data,(res)=>{
          if(res.data.code){
            this.mobile = res.data.data.mobile;
            app.globalData.mobile = res.data.data.mobile;
            this.$emit('returnPhone');
          }else{
            uni.showToast({
                title: '授权失败',
                icon:'error',
                duration: 2000
            });
          }
        })
      }else{
        uni.showToast({
            title: '授权失败',
            icon:'error',
            duration: 2000
        });
      }
      
      // cloudID: "50_jxJk92OFaTLuYAlpxY10kRID2MuvhIwA70Q6hTPCmLFBEndfkFu9MbvGgXA"
      // encryptedData: "/Ut+37gUoDmstuhPFJYLh0y/wu4cAZm/DQHaFgAWI59UlY4IEsWckjZE/tColAhGWn0FFdsuQjzFlcar/pOZ1F5hVIUdAiFPE0ByvA68E12fgxDLlyKUwDZfvaXbS//yHCxE6/4NxMDT4YeusnkI2CxRmyVZRsAm9vBbGvURka96pf4alk7ggJblijLNajy/Yj6SJmG262OhS2Y+DG+nFw=="
      // errMsg: "getPhoneNumber:ok"
      // iv: "+JX5k8oBsWBdwJ8Vsf8VhA=="
    },
    getUserInfo(){
      if(!this.user_openinfo.nickname){
        uni.getUserProfile({
          desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
          success: (res) => {
            uni.showToast({
            	title: '登录中',
            	icon: 'loading',
            	duration: 10000
            });
            ikz.userinfo(res, '', res => {
            	//登录成功，进行赋值
            	uni.hideToast();
            	this.user_openinfo = res.data.user_info;
              app.globalData.user_openinfo = res.data.user_info;
              this.$emit('returnUserInfo',this.user_openinfo);
            });
          },
          fail:(res1)=>{
            uni.showToast({
                title: '授权失败',
                icon:'error',
                duration: 2000
            });
          },
        })
      }
      // 查看是否授权
          // wx.getSetting({
          //   success (res){
          //     if (res.authSetting['scope.userInfo']) {
          //       // 已经授权，可以直接调用 getUserInfo 获取头像昵称
               
          //     }
          //   }
          // })
      // console.log(e)
    }
	}
};
</script>

<style scoped>
.ikz-login{
  position: absolute;
  top:0px;
  left:0px;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding-top: 50rpx;
}
.ikz-login-btn{
  position: absolute;
  top:0px;
  left:0px;
  width: 100%;
  height: 100%;
  opacity: 0;
  z-index: 999;
}
</style>
